package com.atguigu.controller;

import com.atguigu.pojo.Delivery;
import com.atguigu.pojo.User;
import com.atguigu.service.DeliveryService;
import com.atguigu.service.impl.DeliveryServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/delivery/Add")
public class UserDeliveryAddController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("user_name");
        User user = (User) req.getSession().getAttribute("Session_User");
        Integer companyId = Integer.valueOf(req.getParameter("cat_id"));
        String phone = req.getParameter("user_phone");
        String address = req.getParameter("address");
        String date = req.getParameter("date");
        Integer status =Integer.valueOf(req.getParameter("a"));
        DeliveryService deliveryService = new DeliveryServiceImpl();
        Delivery delivery = deliveryService.addDelivery(username,user.getId(),companyId,phone,address,date,status);
        System.out.println("新增的快递信息是：\n"+delivery);
        resp.sendRedirect("/delivery/List");
    }
}
